﻿using AdminSystem.Application.Admins;
using AdminSystem.Application.Admins.Dto;
using AdminSystem.Domain;
using AdminSystem.EntityFrameworkCore;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace AdminSystem.WebApi.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    [Authorize]
    [ApiExplorerSettings(GroupName = "v1")]

    public class TestController : ControllerBase
    {
        private readonly IAdminService adminService;
        private readonly IConfiguration configuration;

        public TestController(IAdminService adminService, IConfiguration configuration)
        {
            this.adminService = adminService;
            this.configuration = configuration;
        }

        [HttpPost]
        public async Task<IActionResult> Index(CreateUpdateAdminDto createUpdateAdminDto) 
        { 
            var dto = await adminService.CreateAsync(createUpdateAdminDto);
            return Ok(dto);
        }

        [HttpDelete]

        public async Task<IActionResult> DeleteAsync(int Id)
        {
            return Ok(await adminService.DeleteAsync(Id));
        }

        /// <summary>
        /// 获取用户信息
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> GetUserInfo()
        {
            adminService.GetUserInfo();

            return Ok();
        }

        [HttpGet]
        [AllowAnonymous]

        public async Task<IActionResult> QueryAsync(int Id)
        {
            return new JsonResult(await adminService.QueryAsync());
        }


        [HttpGet]
        [AllowAnonymous]
        public async Task<IActionResult> HelloWorldAsync()
        {
            ServiceReference1.WebService1SoapClient client = new ServiceReference1.WebService1SoapClient(ServiceReference1.WebService1SoapClient.EndpointConfiguration.WebService1Soap);
            var result = await client.HelloWorldAsync();
            return Ok(result.Body.HelloWorldResult);
        }
    }
}
